# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=xerces-c
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.0
pkgrel=2
pkgdesc="A validating XML parser written in a portable subset of C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://xerces.apache.org/xerces-c"
msys2_references=(
  "cpe: cpe:/a:apache:xerces-c%2b%2b"
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         # "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-icu")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://archive.apache.org/dist/xerces/c/3/sources/xerces-c-${pkgver}.tar.gz"
        001-no-undefined.patch
        002-duplicate-instantiation.patch
        003-makefile-add-ws2_32.patch
        004-check-cpuid-header-for-arm64.patch)
sha256sums=('9555f1d06f82987fbb4658862705515740414fd34b4db6ad2ed76a2dc08d3bde'
            'a95206b0e17942ebe5bffcafbb9c9555b1f3c922b9a8f7cdea950acab48eecd5'
            '028b0a5c021d63c74db24bfca898c9e6df7074c1597896a6bfd48d76f64b9cb8'
            '28f8dd21779453ebedaf6aba0fee0502e11e3fc22f805c6ede09162222810e69'
            '9ee9437b0fe336972bcf979d8aedff172287a802eb302768fb17e44e616783d4')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-no-undefined.patch
  patch -p1 -i "${srcdir}"/002-duplicate-instantiation.patch
  patch -p1 -i "${srcdir}"/003-makefile-add-ws2_32.patch
  patch -p1 -i "${srcdir}"/004-check-cpuid-header-for-arm64.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
